package sistema.validador;
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 29/3/2006 21:06:19
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Diff.java

import java.io.*;

public class Diff extends ValidatorInitialSpace
{

    public int diffone(String client, String judge, PrintWriter log)
    {
        log.println("-------------------------***STARTING DIFF ( " + client + " " + judge + " )***-----------------------");
        boolean continue_on = true;
        boolean actually_equal = false;
        int result = -1;
        int count = 1;
        try
        {
            BufferedReader brclient = new BufferedReader(new FileReader(client));
            try
            {
                BufferedReader brjudge = new BufferedReader(new FileReader(judge));
                try
                {
                    String line = brjudge.readLine();
                    log.println(" Team Line is  : " + line);
                    try
                    {
                        String line2 = brclient.readLine();
                        log.println(" Answer Line is: " + line2);
                        try
                        {
                            while((line != null || line2 != null) && continue_on) 
                            {
                                if(line != null && line2 == null)
                                {
                                    for(String temp = brjudge.readLine(); temp != null; temp = brjudge.readLine())
                                        log.println(" The output file terminated but judges file still has " + temp);

                                    return -1;
                                }
                                if(line == null && line2 != null)
                                    return 0;
                                count++;
                                if(line.equals(line2))
                                {
                                    log.println("LINES ARE EQUAL. ");
                                } else
                                {
                                    log.println("FILES " + judge + " AND " + client + " ARE DIFFERENT");
                                    log.println("RESULT :");
                                    log.println("THE FILES " + client + " & " + judge + " ARE DIFFERENT AT LINE NO : " + (count - 1));
                                    log.println();
                                    log.println("THE JUDGE'S FILE AT THIS LINE READS: " + line);
                                    log.println();
                                    log.println("THE TEAM'S  FILE AT THIS LINE READS: " + line2);
                                    log.println();
                                    log.println("TEMINATING DIFF..............");
                                    log.println();
                                    log.println("STARTING DIFF IGNORE SPACE CARRIAGE TO VALIDATE THE TWO FILES AND FIND POSSIBILIY OF FORMAT ERROR");
                                    continue_on = false;
                                    return 0;
                                }
                                line = brjudge.readLine();
                                log.println(" Team Line is  : " + line);
                                line2 = brclient.readLine();
                                log.println(" Answer Line is: " + line2);
                            }
                            actually_equal = true;
                        }
                        catch(IOException e)
                        {
                            System.out.println("FAILED TO EXECUTE WHILE LOOP IN DIFF1" + e.toString());
                            log.println("FAILED TO EXECUTE WHILE LOOP IN DIFF1" + e.toString());
                        }
                    }
                    catch(IOException e)
                    {
                        System.out.println("POSSIBLY FAILED TO CREATE CLIENT'S BUFFERED READER. " + e.toString());
                        log.println("POSSIBLY FAILED TO CREATE CLIENT'S BUFFERED READER. " + e.toString());
                    }
                }
                catch(IOException e)
                {
                    System.out.println("POSSIBLY FAILED TO CREATE JUDGES'S BUFFERED READER. " + e.toString());
                    log.println("POSSIBLY FAILED TO CREATE JUDGES'S BUFFERED READER. " + e.toString());
                }
            }
            catch(IOException e)
            {
                System.out.println("POSSIBLY FAILED TO OPEN THE CLIENT'S FILE. File Name: " + client + "EXCEPTION THROWN :" + e.toString());
                log.println("POSSIBLY FAILED TO OPEN THE CLIENT'S FILE. File Name: " + client + "EXCEPTION THROWN :" + e.toString());
            }
        }
        catch(IOException e)
        {
            System.out.println("POSSIBLY FAILED TO OPEN THE JUDGES FILE. File Name: " + judge + " EXCEPTION THROWN :" + e.toString());
            log.println("POSSIBLY FAILED TO OPEN THE JUDGES FILE. File Name: " + judge + " EXCEPTION THROWN :" + e.toString());
        }
        log.println("-------------------------***EXITING DIFF***-----------------------");
        if(continue_on && actually_equal)
        {
            log.println("THE FILES " + client + " & " + judge + " ARE EQUAL");
            log.println("SETTING THE  APPROPRIATE FLAGS....");
            return 1;
        } else
        {
            return result;
        }
    }

    public Diff()
    {
        diffDescription = "No Comments.. \n See log file.";
    }

    public Diff(ValidatorSpace vs, String token)
    {
        diffDescription = "No Comments.. \n See log file.";
        if("-PC2".equals(token.toUpperCase()))
            vs.setGlobalValidator(true);
    }

    public int diffoneIgnoreCase(String client, String judge, PrintWriter log)
    {
        log.println("-------------------------***STARTING DIFF ( " + client + " " + judge + " )***-----------------------");
        boolean continue_on = true;
        boolean actually_equal = false;
        int result = -1;
        int count = 1;
        try
        {
            BufferedReader brclient = new BufferedReader(new FileReader(client));
            try
            {
                BufferedReader brjudge = new BufferedReader(new FileReader(judge));
                try
                {
                    String line = brjudge.readLine();
                    log.println(" Team Line is  : " + line);
                    try
                    {
                        String line2 = brclient.readLine();
                        log.println(" Answer Line is: " + line2);
                        try
                        {
                            while((line != null || line2 != null) && continue_on) 
                            {
                                if(line != null && line2 == null)
                                {
                                    for(String temp = brjudge.readLine(); temp != null; temp = brjudge.readLine())
                                        log.println(" The output file terminated but judge's file still has " + temp);

                                    return -1;
                                }
                                if(line == null && line2 != null)
                                    return 0;
                                count++;
                                if(line.equalsIgnoreCase(line2))
                                {
                                    log.println("FILES ARE EQUAL. ");
                                } else
                                {
                                    log.println("FILES " + judge + " AND " + client + " ARE DIFFERENT");
                                    log.println("RESULT :");
                                    log.println("THE FILES " + client + " & " + judge + " ARE DIFFERENT AT LINE NO : " + (count - 1));
                                    log.println();
                                    log.println("THE JUDGE'S FILE AT THIS LINE READS: " + line);
                                    log.println();
                                    log.println("THE TEAM'S  FILE AT THIS LINE READS: " + line2);
                                    log.println();
                                    log.println("TEMINATING DIFF..............");
                                    log.println();
                                    log.println("STARTING DIFF IGNORE SPACE CARRIAGE TO VALIDATE THE TWO FILES AND FIND POSSIBILIY OF FORMAT ERROR");
                                    return 0;
                                }
                                line = brjudge.readLine();
                                log.println(" Team Line is  : " + line);
                                line2 = brclient.readLine();
                                log.println(" Answer Line is: " + line2);
                            }
                            actually_equal = true;
                        }
                        catch(IOException e)
                        {
                            System.out.println("FAILED TO EXECUTE WHILE LOOP IN DIFF1" + e.toString());
                            log.println("FAILED TO EXECUTE WHILE LOOP IN DIFF1" + e.toString());
                        }
                    }
                    catch(IOException e)
                    {
                        System.out.println("POSSIBLY FAILED TO CREATE CLIENT'S BUFFERED READER. " + e.toString());
                        log.println("POSSIBLY FAILED TO CREATE CLIENT'S BUFFERED READER. " + e.toString());
                    }
                }
                catch(IOException e)
                {
                    System.out.println("POSSIBLY FAILED TO CREATE JUDGES'S BUFFERED READER. " + e.toString());
                    log.println("POSSIBLY FAILED TO CREATE JUDGES'S BUFFERED READER. " + e.toString());
                }
            }
            catch(IOException e)
            {
                System.out.println("POSSIBLY FAILED TO OPEN THE CLIENT'S FILE. File Name: " + client + "EXCEPTION THROWN :" + e.toString());
                log.println("POSSIBLY FAILED TO OPEN THE CLIENT'S FILE. File Name: " + client + "EXCEPTION THROWN :" + e.toString());
            }
        }
        catch(IOException e)
        {
            System.out.println("POSSIBLY FAILED TO OPEN THE JUDGES FILE. File Name: " + judge + " EXCEPTION THROWN :" + e.toString());
            log.println("POSSIBLY FAILED TO OPEN THE JUDGES FILE. File Name: " + judge + " EXCEPTION THROWN :" + e.toString());
        }
        log.println("-------------------------***EXITING DIFF***-----------------------");
        if(continue_on && actually_equal)
        {
            log.println("THE FILES " + client + " & " + judge + " ARE EQUAL");
            log.println("SETTING THE  APPROPRIATE FLAGS....");
            return 1;
        } else
        {
            return result;
        }
    }

    public String getDiffDescription()
    {
        return diffDescription;
    }

    private void setDiffDescription(String newDiffDescription)
    {
        diffDescription = newDiffDescription;
    }

    private String diffDescription;
}